package com.terry.test3;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 篮球比赛
 *
 * 暴力DFS枚举
 *
 * @author 小八
 * @date 2023年02月09日17:53
 */
public class Title12 {

    public static void main(String[] args) {
        int[] nums = new int[]{1,2,3,4,5,8,9,10};
        minimumDifference(nums);
    }

    public static int minimumDifference(int[] nums) {
        int total = 0;
        for (int i = 0; i < nums.length; i++) {
            total += nums[i];
        }
        Arrays.sort(nums);
        List<Integer> tempResult = new ArrayList<>();
        calc(tempResult,nums,0,0,0,nums.length/2,total);
        int minScore = Integer.MAX_VALUE;
        for (int i = 0; i < tempResult.size(); i++) {
            minScore = Math.min(minScore,tempResult.get(i));
        }
        System.out.println(minScore);
        return minScore;
    }

    public static void calc(List<Integer> tempResult,int[] nums,int index,int score,int len,int totalLen,int totalScore){
        if(len == totalLen){
            System.out.println(score);
            tempResult.add(Math.abs(totalScore-2*score));
            return ;
        }
        for (int i =index;i<nums.length;i++){
            score = score + nums[i];
            calc(tempResult,nums,i+1,score,len+1,totalLen,totalScore);
            score = score - nums[i];
        }
    }
}
